import {ref, reactive, computed} from "vue";

export function usePileForm() {
    const addDialogVisible = ref(false);      // 在这里定义
    const openAddDialog = () => {
        addDialogVisible.value = true;
        // 如果要重置表单，也可写在这里
    };

    const addForm = reactive({
        id: null,
        pileName: "", // pile_name
        pileCode: "", // pile_code
        pileType: "", // pile_type
        pilePower: null, // pile_power
        pileModel: "", // pile_model
        pileDesc: "", // pile_desc
        suitableVehicle: "", // suitable_vehicle
        pileStatus: "空闲中", // 默认空闲
        stationId: null, // station_id
        chargingGunCount: 0,
        chargingGuns: [],
    });

    const chargingGunsCount = computed(() => {
        return Array.isArray(addForm.chargingGuns)
            ? addForm.chargingGuns.length
            : 0;
    });

    return {
        addForm,
        chargingGunsCount,
        addDialogVisible,
        openAddDialog,
    };
}
